package com.frank.swagger2.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 小石潭记
 * @date 2020/10/27 16:24
 * @Description: ${todo} 配置了swagger文档 启动报错~ 找不到feign-client
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
// http://localhost:8080/swagger-ui.html 原生的swagger地址
// http://localhost:8080/doc.html#/home  换了皮肤的swagger地址
public class Swagger2 {

    @Bean
    public Docket createRestApi(){
        List<Parameter> parameters = new ArrayList<>();
        parameters.add(new ParameterBuilder()
                .name("token")
                .description("认证token")
                .modelRef(new ModelRef("string"))
                .parameterType("header")
                .defaultValue("这是默认值-----")
                .required(false)
                .build());
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("SpringBoot1.0 API")
                .apiInfo(apiInfo())
                .globalOperationParameters(parameters)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.frank"))
                .paths(PathSelectors.any())
                .build();
    }

    public ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("spring boot利用swagger构建api文档")
                .description("简单优雅的rest风格")
                .termsOfServiceUrl("http://localhost:8080")//文档遵循的开发协议的展现网址
                .version("1.0")//版本
                .build();
    }
}
